package routers

import (
	"drtm/controller"
	"drtm/middleware"
	"drtm/setting"

	"github.com/gin-gonic/gin"
)

// SetupRouter 设置路由
func SetupRouter() *gin.Engine {
	authMiddleware := middleware.SetupAuthMiddleware()
	if setting.Conf.Release {
		gin.SetMode(gin.ReleaseMode)
	}
	r := gin.Default()
	r.POST("/login", authMiddleware.LoginHandler)
	r.GET("/refresh_token", authMiddleware.RefreshHandler)
	r.GET("/logout", authMiddleware.LogoutHandler)
	// v1
	v1Group := r.Group("admin").Use(middleware.Recover).Use(authMiddleware.MiddlewareFunc())
	{
		v1Group.POST("/user", controller.CreateUser)
		v1Group.GET("/user", controller.GetAllUser)
		v1Group.PUT("/user/:id", controller.UpdateAUser)
		v1Group.DELETE("/user/:id", controller.DeleteAUser)
	}
	return r
}
